package com.xiaoxi.exam.controller;

import com.xiaoxi.exam.bean.request.WxPayResultNotifyRequest;
import com.xiaoxi.exam.bean.response.WxPayResultNotifyResponse;
import com.xiaoxi.exam.service.OrderService;
import com.xiaoxi.exam.utils.XMLUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/notify")
@Slf4j
public class WXNotify {

  @Autowired
  private OrderService orderService;

  @PostMapping(value = "/wx")
  public String WXPayNotify(@RequestBody WxPayResultNotifyRequest request) {
    log.info("WX pay notify ...");
    WxPayResultNotifyResponse wxPayResultNotifyResponse = orderService.handleWXNotify(request);
    return XMLUtils.toXml(wxPayResultNotifyResponse, "xml", WxPayResultNotifyResponse.class);
  }

}
